class Solution:
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """

        n = len(prices)
        if n==0:
            return 0

        no_gupiao = [0] * n
        have_gupiao = [0] * n

        have_gupiao[0] =  -prices[0]
        for i in range(1,n):
            no_gupiao[i] = max(no_gupiao[i-1],have_gupiao[i-1]+prices[i])
            have_gupiao[i] = have_gupiao[i-1]
            have_gupiao[i] = max(have_gupiao[i],(no_gupiao[i-2] if i>=2 else 0)-prices[i])
        return no_gupiao[-1]


a = [2,1]
s=Solution()
m =s.maxProfit(a)
print(m)